package br.com.vti.sisp_sicrim.controller;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Qualifier;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;
import br.com.crud4j.core.model.business.Business;
import br.com.crud4j.core.util.MessageResolver;
import br.com.crud4j.vraptor3.controller.ControllerImpl;
import br.com.vti.sisp_sicrim.model.entity.Endereco;
import br.com.vti.sisp_sicrim.model.entity.Estado;
import br.com.vti.sisp_sicrim.model.entity.Municipio;
import br.com.vti.sisp_sicrim.model.entity.TipoLogradouro;
import br.com.vti.sisp_sicrim.model.entity.enums.Status;
import br.com.vti.sisp_sicrim.modelo.business.exception.EnderecoException;
import br.com.vti.sisp_sicrim.modelo.business.exception.EstadoException;
import br.com.vti.sisp_sicrim.modelo.business.exception.MunicipioException;
import br.com.vti.sisp_sicrim.modelo.business.exception.TipoLogradouroException;

@Resource
@Path("/pages/endereco")
public class EnderecoController extends ControllerImpl<Endereco, EnderecoException> {

	private final Business<TipoLogradouro, TipoLogradouroException> tipoLogradouroBusiness;
	private final Business<Municipio, MunicipioException> municipioBusiness;
	private final Business<Estado, EstadoException> estadoBusiness;
	
	public EnderecoController(Result result, Validator validator, 
			@Qualifier("tipoLogradouroBusiness") Business<TipoLogradouro, TipoLogradouroException> tipoLogradouroBusiness,
			@Qualifier("enderecoBusiness") Business<Endereco, EnderecoException> entidadeBusiness, 
			@Qualifier("municipioBusiness") Business<Municipio, MunicipioException> municipioBusiness, 
			@Qualifier("estadoBusiness") Business<Estado, EstadoException> estadoBusiness,
			MessageResolver messageResolver) {
		
		super(result, validator, entidadeBusiness, messageResolver);

		this.tipoLogradouroBusiness = tipoLogradouroBusiness;
		this.municipioBusiness = municipioBusiness;
		this.estadoBusiness = estadoBusiness;
		
	}

	protected Business<TipoLogradouro, TipoLogradouroException> getTipoLogradouroBusiness() {
		return tipoLogradouroBusiness;
	}
	
	public Business<Municipio, MunicipioException> getMunicipioBusiness() {
		return municipioBusiness;
	}
	
	public Business<Estado, EstadoException> getEstadoBusiness() {
		return estadoBusiness;
	}

	@Override
     @Get(value={"novo","buscar/{entidade.id}"})
     public void cadastrar(Endereco entidade) {
    	super.cadastrar(entidade);
    	include("tipoLogradouroList", tipoLogradouroBusiness.listar(null));
    	include("municipioList", municipioBusiness.listar(null));
    	include("estadoList", estadoBusiness.listar(null));
    	include("statusList", Arrays.asList(Status.values()));
     }
	 
	 

}